package com.tianyue.overlordgame.ui.login.model;

import android.app.Application;
import android.databinding.ObservableBoolean;
import android.databinding.ObservableField;
import android.databinding.ObservableInt;
import android.support.annotation.NonNull;
import android.text.TextUtils;
import android.view.View;

import com.tianyue.overlordgame.config.CommonTags;
import com.tianyue.overlordgame.ui.commonmodel.CommonSIMCodeViewModel;
import com.tianyue.overlordgame.ui.login.RegisterActivity;

import me.goldze.mvvmhabit.binding.command.BindingCommand;
import me.goldze.mvvmhabit.utils.ToastUtils;

public class LoginViewModel extends CommonSIMCodeViewModel {
    public LoginViewModel(@NonNull Application application) {
        super(application);
    }

    private int mCurrentLoginType = CommonTags.LOGIN_TYPE.PWD;
    //密码
    public ObservableField<String> pwd_text = new ObservableField<>("");
    //显示密码登录框
    public ObservableInt isPwdLoginShow = new ObservableInt(View.VISIBLE);
    public ObservableBoolean loginType_pwd_select = new ObservableBoolean(true);
    public ObservableBoolean loginType_sim_code_select = new ObservableBoolean(false);
    //隐藏短信登录款
    public ObservableInt isSimLoginShow = new ObservableInt(View.GONE);
    //密码可见->改变图片切换&输入框是否可见
    public ObservableBoolean pwd_is_can_see = new ObservableBoolean(false);
    //账户密码登录
    public BindingCommand loginType_pwd = new BindingCommand(() -> {
        isPwdLoginShow.set(View.VISIBLE);
        isSimLoginShow.set(View.GONE);
        mCurrentLoginType = CommonTags.LOGIN_TYPE.PWD;
        loginType_pwd_select.set(true);
        loginType_sim_code_select.set(false);
    });
    //手机动态码登录
    public BindingCommand loginType_sim_code = new BindingCommand(() -> {
        isPwdLoginShow.set(View.GONE);
        isSimLoginShow.set(View.VISIBLE);
        mCurrentLoginType = CommonTags.LOGIN_TYPE.SIM;
        loginType_pwd_select.set(false);
        loginType_sim_code_select.set(true);
    });
    //微信登录
    public BindingCommand loginType_vx = new BindingCommand(() -> {
        ToastUtils.showShort("微信登录");
    });
    //qq登录
    public BindingCommand loginType_qq = new BindingCommand(() -> {
        ToastUtils.showShort("qq登录");
    });

    //密码是否可见点击
    public BindingCommand pwd_is_see = new BindingCommand(() -> {
        pwd_is_can_see.set(!pwd_is_can_see.get());
        //TODO 密码是否可见
    });
    //发送验证码
    public BindingCommand send_code = new BindingCommand(() -> {
        super.requestSmsCode(CommonTags.SIM_CODE_LOGIN);
    });
    //登录按钮
    public BindingCommand login = new BindingCommand(() -> {
        if (TextUtils.isEmpty(phone_num_text.get())) {
            ToastUtils.showShort("请输入手机号码");
            return;
        }
        switch (mCurrentLoginType) {
            case CommonTags.LOGIN_TYPE.PWD://密码
                if (TextUtils.isEmpty(pwd_text.get())) {
                    ToastUtils.showShort("请输入密码");
                    return;
                }
                ToastUtils.showShort("do Login");
                break;
            case CommonTags.LOGIN_TYPE.SIM://短信
                if (TextUtils.isEmpty(sim_code_text.get())) {
                    ToastUtils.showShort("请输入验证码");
                    return;
                }
                ToastUtils.showShort("do Login");
                break;
        }
    });
    //注册新用户按钮
    public BindingCommand register_new_account = new BindingCommand(() -> {
        startActivity(RegisterActivity.class);
    });
    //找回密码
    public BindingCommand forget_pwd = new BindingCommand(() -> {
        ToastUtils.showShort("找回密码");
    });

}
